package com.musicalevents.authentication;

import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

public class CustomUserDetails implements UserDetails {

	private static final long serialVersionUID = -411204292760065181L;
	private int id;
	private String username;
	private String password;
	private boolean accountExpiration;
	private boolean accountLock;
	private boolean credentialsExpiration;
	private boolean state;
	private Collection<? extends GrantedAuthority> authorities;
	
	/**
	 * User constructor. See org.springframework.security.core.userdetails.UserDetails for more details.
	 * @param username Username.
	 * @param accountExpiration Account expirated.
	 * @param accountLock Account locked.
	 * @param credentialsExpiration Credentials expirated.
	 * @param enabled Account enabled.
	 */
	public CustomUserDetails(int userID,
			String username,
			String password,
			boolean accountExpiration,
			boolean accountLock,
			boolean credentialsExpiration,
			boolean enabled) {
		this.id = userID;
		this.username = username;
		this.password = password;
		this.accountExpiration = accountExpiration;
		this.accountLock = accountLock;
		this.credentialsExpiration = credentialsExpiration;
		this.state = enabled;
	}	
	
	/**
	 * Setter used to define user authorities outside of the constructor.
	 * @param collection Authorities of the user (Roles).
	 */
	public void setAuthorities(Collection<? extends GrantedAuthority> collection) {
		this.authorities = collection;
	}
	
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return (this.authorities);
	}

	public int getID() {
		return (this.id);
	}
	
	public String getPassword() {
		return (this.password);
	}

	public String getUsername() {
		return (this.username);
	}

	public boolean isAccountNonExpired() {
		return (this.accountExpiration);
	}

	public boolean isAccountNonLocked() {
		return (this.accountLock);
	}

	public boolean isCredentialsNonExpired() {
		return (this.credentialsExpiration);
	}

	public boolean isEnabled() {
		return (this.state);
	}
}
